package com.cdzy.controller;

import com.cdzy.pojo.BookTypes;
import com.cdzy.service.BookTypesService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;



/**
 * 图书分类表(BookTypes)表控制层
 *
 * @author makejava
 * @since 2025-04-01 10:04:16
 */
@RestController
@RequestMapping("/bookTypes")
@CrossOrigin
public class BookTypesController {
    /**
     * 服务对象
     */
    @Resource
    private BookTypesService bookTypesService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public ResponseEntity<BookTypes> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.bookTypesService.queryById(id));
    }


    /**
     * 新增数据
     *
     * @param bookTypes 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public ResponseEntity<BookTypes> add(@RequestBody BookTypes bookTypes) {
        return ResponseEntity.ok(this.bookTypesService.insert(bookTypes));
    }

    /**
     * 编辑数据
     *
     * @param bookTypes 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public ResponseEntity<BookTypes> edit(@RequestBody BookTypes bookTypes) {
        return ResponseEntity.ok(this.bookTypesService.update(bookTypes));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable  Integer id) {
        return ResponseEntity.ok(this.bookTypesService.deleteById(id));
    }

}

